﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using popLib;
using PhotoMgr.src.common;
using System.Windows.Forms;
using System.Data;
using PhotoMgr.src.gui.photo;

namespace PhotoMgr.src.database
{
    public partial class DBManager
    {
        public static View_RoundImage RoundImage_GetByRoundImageID(int roundImageID, int userID)
        {
            using (var entity = new PhotoMgrEntities(GenConnectionString()))
            {
                var rs = entity.View_RoundImage.Where(x => x.RoundImageID == roundImageID);
                View_RoundImage item = rs.First();
                item.Score = item.SubScore = item.ThirdScore = 0;

                var rs1 = entity.ImageScores.Where(x => x.RoundImageID == roundImageID && x.UserID == userID);
                if (rs1.Count() > 0)
                {
                    item.Score = (double)rs1.First().Score;
                    item.SubScore = rs1.First().SubScore == null ? 0 : (double)rs1.First().SubScore;
                    item.ThirdScore = rs1.First().ThirdScore == null ? 0 : (double)rs1.First().ThirdScore;
                }

                return item;
            }
        }

        public static bool ImageScore_IsScoreAll(int roundImageID, ScoreType scoretype)
        {
            using (var entity = new PhotoMgrEntities(GenConnectionString()))
            {
                return (bool)entity.ImageScore_IsScoredAll(roundImageID, Convert.ToInt16(scoretype) ).ToList().First().Value;
            }
        }

        public static bool KiemTraDuLieu_Round(int round_id)
        {
            var entity = new PhotoMgrEntities(GenConnectionString());

            IQueryable<database.RoundImage> result = entity.RoundImages.Where(x => x.Round.RoundID == round_id);

            if (result.Count() > 1)
            {
                return true;
            } 
            return false;
        }
    }
}
